package cn.anecansaitin.whimsy.common.listener;

import cn.anecansaitin.whimsy.Whimsy;
import cn.anecansaitin.whimsy.common.capabilities.battle.BattleMode;
import cn.anecansaitin.whimsy.common.capabilities.battle.IBattleMode;
import net.minecraft.server.level.ServerPlayer;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;

@Mod.EventBusSubscriber(modid = Whimsy.MODID)
public class OnPlayerLoggedOut {
    @SubscribeEvent
    public static void onPlayerLoggedOut(PlayerEvent.PlayerLoggedOutEvent event) {
        ServerPlayer player = (ServerPlayer) event.getEntity();
        //当玩家离开存档后，检查战斗模式能力，并关闭战斗模式
        IBattleMode iBattleMode = player.getCapability(IBattleMode.BATTLE_MODE);

        if (iBattleMode instanceof BattleMode battleMode) {
            battleMode.setMode(false);
        }
    }
}
